﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Net;

namespace NASA.BeAMartian.Views.Explore
{

    public partial class EventInfo : Canvas
    {
        private Storyboard _fadeIn;
        private EventData _eventData;

        public EventData EventDetails
        {
            get { return _eventData; }
        }

        public EventInfo()
        {
            InitializeComponent();

            _fadeIn = (Storyboard)(Resources["FadeIn"]);
        }

        /// <summary>
        /// Show the control and fade in the logo.
        /// </summary>
        public void Show()
        {
            ((Storyboard)Resources["TextFadeIn"]).Begin();
        }

        /// <summary>
        /// Show the control and fade in the logo.
        /// </summary>
        public void SetData(EventData eventData)
        {
            _info.Opacity = 0;
            _eventData = eventData;
            _info.Text = eventData.Info;
        }

        /// <summary>
        /// Hide the control.
        /// </summary>
        public void Hide()
        {
            _info.Opacity = 0;
        }

        /// <summary>
        /// Download the image from the server.
        /// </summary>
        /// <param name="uri"></param>
        private void DownloadEventImage(Uri uri)
        {
            WebClient download = new WebClient();

            download.OpenReadCompleted += Download_OpenReadCompleted;
            download.OpenReadAsync(uri);
        }

        /// <summary>
        /// Handle image download completion.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Download_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            //If (Visibility=Visibility.Visible) AndAlso (e.Error Is Nothing) AndAlso (Not e.Cancelled) Then
            //	_teaser.Visibility = Visibility.Visible
            //	_eventImageSource.SetSource(e.Result)
            //	_fadeIn.Begin()
            //End If
        }
    }

    /// <summary>
    /// Display data for a global event.
    /// </summary>
    public class EventData
    {
        private string privateTitle;
        public string Title
        {
            get
            {
                return privateTitle;
            }
            private set
            {
                privateTitle = value;
            }
        }

        private string privateInfo;
        public string Info
        {
            get
            {
                return privateInfo;
            }
            private set
            {
                privateInfo = value;
            }
        }

        private string privateImagePath;
        public string ImagePath
        {
            get
            {
                return privateImagePath;
            }
            private set
            {
                privateImagePath = value;
            }
        }

        public EventData(string name, string info, string imagePath)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

            if (imagePath == null)
            {
                throw new ArgumentNullException("imagePath");
            }

            Title = name;
            this.Info = info;
            this.ImagePath = imagePath;
        }

        public EventData(BeAMartian.Views.Explore.RegionType rt, string description)
        {
            Title = rt.Description();
            this.Info = description;
        }
    }


}
